﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HF.BaseWebCtrlLib;
using HF.Business.Common;//一个业务模块的公共类
using HF.Framework;//框架类
using HF.WorkFlow.Const;
using HF.Framework.DataClientDBAgent;
using HF.Business.Sale;//封装销售业务的类

public partial class SaleRetailAudit : BaseUserControl
{
    string BillCode = "";
    string BillAudit = "";

    protected void Page_Load(object sender, EventArgs e)
    {

        initData();
    }
    private void initData()
    {
        DataTable dt = SaleRetail.GetSaleRetailTable(WorkflowInsId);
        if (dt != null && dt.Rows.Count > 0)
        {
            BillCode = dt.Rows[0]["Bill_Code"].ToString();
            BillAudit = dt.Rows[0]["Bill_AuditFlag"].ToString();
            if (BillCode.Length == 0)
            {
                throw new Exception("SaleRetailAudit Bill_Code 不能为空!");         
            }

            if (BillAudit == "0")
            {
                rbtnYes.Checked = true;

            }
            else
                if (BillAudit == "2")
                {
                    rbtnYuzhan.Checked = true;

                }
                else
                    if (BillAudit == "3") rbtnNo.Checked = true;

        }
    }
    
    public override void SaveUserControl(bool IsDraft)
    {  
        base.SaveUserControl(IsDraft);
        try
        {

            //直接出库
            if (rbtnYes.Checked == true)
            {
                
                if (IsDraft == false && this.CtrlState != WorkFlowConst.STATE_VIEW)//不是草稿
                {
                   
                      SaleRetail.SaleRetailOutStore(BillCode, UserId, UserName);
                }
            }
            else//预占库存
                if (rbtnYuzhan.Checked == true)
                {
                    if (IsDraft == false && this.CtrlState != WorkFlowConst.STATE_VIEW)//不是草稿
                        SaleRetail.SaleRetailYuzhanStore(BillCode, UserId, UserName);
                }

                else
                    if (rbtnNo.Checked == true)
                    {
                        if (IsDraft == false && this.CtrlState != WorkFlowConst.STATE_VIEW)//不是草稿
                            SaleRetail.SaleRetailAuditNoPass(BillCode, UserId, UserName);
                    }

        }
        catch
        {
            throw;
        }
    }
   
}
